﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using ImageRecognition2.Forms;
using System.Windows.Forms;

using LowLevelGraphics;
using LowLevelGraphics.Filter;

namespace ImageRecognition2.Action
{
    /// <summary>
    /// Bar code action
    /// </summary>
    public class ActionBarcode : AbstractCommand
    {
        private PictureBox m_PictureBox = null;
        
        /// <summary>
        /// Initializes a new instance of the <see cref="ActionBarcode"/> class.
        /// </summary>
        public ActionBarcode()
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="ActionBarcode"/> class.
        /// </summary>
        /// <param name="_actionBarcode">The _action barcode.</param>
        internal ActionBarcode(ActionBarcode _actionBarcode)
        {
            this.m_PictureBox = _actionBarcode.m_PictureBox;
        }

        /// <summary>
        /// Runs the specified sender.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        public override void Run(object sender, EventArgs e)
        {
            FormThresholdInput formBarcodeInput = new FormThresholdInput();
            if (formBarcodeInput.ShowDialog() == DialogResult.OK)
            {
                Bitmap bitmap = (Bitmap)MainFormSingleton.ActivePictureBox.BackgroundImage;
                UnsafeBitmap unsafeBitmap = new BarcodeFilter(formBarcodeInput.Threshold, formBarcodeInput.ThresholdOnly).Execute(bitmap);
                unsafeBitmap.Dispose();
            }
        }

        public override object Clone()
        {
            return new ActionBarcode(this);
        }
    }
}
